package com.zjsru.leetcode75.level1;

/**
 * @Author: CookLee
 * @Date: 2022/10/30
 * 判断子序列
 * 字符串的一个子序列是原始字符串删除一些（也可以不删除）字符而不改变剩余字符相对位置形成的新字符串。（例如，"ace"是"abcde"的一个子序列，而"aec"不是）。
 *
 * 输入：s = "abc", t = "ahbgdc"
 * 输出：true
 *
 * 输入：s = "axc", t = "ahbgdc"
 * 输出：false
 */
public class IsSubsequence {
    
    /**
     * 双指针
     */
    public boolean isSubsequence(String s, String t) {
        int n = s.length();
        int m = t.length();
        int i = 0, j = 0;
        while (i < n && j < m) {
            if (s.charAt(i) == t.charAt(j)) {
                i++;
            }
            j++;
        }
        return i == n;
    }
    
    public static void main(String[] args) {
        IsSubsequence subsequence = new IsSubsequence();
        String s = "abc";
        String t = "ahbgdc";
        System.out.println(subsequence.isSubsequence(s, t));
    }
}
